package com.cupdata.zicon.chain;

import java.util.ArrayList;
import java.util.List;

/**
 * 只去不回的过滤器链的实现
 */
public class FilterChainImpl implements FilterChain{
    private List<Filter> filters=new ArrayList<Filter>();
    /**
     * 记录过滤器的下标
     */
    private int index=0;

    public FilterChainImpl addFilter(Filter filter){
        filters.add(filter);
        return this;
    }

    @Override
    public void doFilter(Request request, Response response) {
        if(index>=filters.size()){
            return;
        }
        index++;
        filters.get(index-1).doFilter(request,response,this);
    }
}
